<template>
	<view>
		<image class="bcg" src="/static/ibcg.png" mode=""></image>
		<view class="content">
			<view class="imgblock">
				<image src="/static/wz.png" mode=""></image>
				<view class="ttt">查报价·上梦商</view>
			</view>
			<view class="top_text">真实变现价，快速比价报价；让梦幻价值看得见！</view>
			<view class="item_b flex" @click="$pageTo(`/pages/index/newsearch?type=1`)">
				<image src="/static/zs.png" mode=""></image>
				<view class="tr flex_jc_sb">
					<view class="">看看现货商人售价</view>
					<uni-icons type="right" size="22" color="#979797"></uni-icons>
				</view>
			</view>
			<view class="item_b flex" @click="$pageTo(`/pages/index/newsearch?type=2`)">
				<image src="/static/zs1.png" mode=""></image>
				<view class="tr flex_jc_sb">
					<view class="">看看收购商人变现价</view>
					<uni-icons type="right" size="22" color="#979797"></uni-icons>
				</view>
			</view>
		</view>

		<uni-popup type="center" ref="popup5" :animation="false" :safe-area="false">
			<view class="popup5">
				<view class="contetn">
					<uni-icons @click="close5()" class="icon" size="24" type="closeempty"></uni-icons>
					<view class="title">温馨提示</view>
					<view class="ts">您当前有正在交易中的订单</view>
					<view class="btns_flex">
						<view class="b1" @click="close5()">关闭</view>
						<view class="b2" @click="gourl()">立即查看</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view> 
</template>

<script>
import { login, messageSeecount, webconfig, inputSearch, getEidToken, getorder } from '@/common/http.api.js';
export default {
	data() {
		return {
			pathID: 0
		};
	},
	onLoad() {
		if (uni.getStorageSync('userToken')) {
			this.gorder();
		} else {
			this.handleLogin();
		}
	},
	onShow() {
		this.gorder();
		this.getSeeCount()
		this.getwebconfig()
	},
	methods: {
		gorder() {
			getorder().then((res) => {
				if (res.code == 200 && res.data.exist) {
					this.$refs.popup5.open();
					this.pathID = res.data.order.id;
				}
			});
		},
		gourl() {
			uni.navigateTo({
				url: `/pages/index/newpage/tradinfo?id=${this.pathID}`
			});
			this.close5();
		},
		close5() {
			this.$refs.popup5.close();
		},
		getwebconfig() {
			webconfig({}).then((res) => {
				if (res.code == 200) {
					uni.setStorageSync('webconfig', res.data);
				}
			});
		},
		getSeeCount() {
			messageSeecount({}).then((res) => {
				if (res.code == 200) {
					let num = res.data;
					if (num > 0) {
						uni.setTabBarBadge({
							index: 1,
							text: '新'
						});
					} else {
						uni.removeTabBarBadge({
							index: 1
						});
					}
				}
			});
		},
		handleLogin() {
			uni.login({
				force: true,
				success: (r) => {
					login({
						code: r.code
					}).then((res) => {
						if (res.code == 200) {
							uni.setStorageSync('openId', res.data.openId);
							uni.setStorageSync('userToken', res.data.token);
							uni.setStorageSync('userInfo', res.data);
							uni.setStorageSync('loginTime', new Date().getTime());
							this.gorder();
							this.getSeeCount()
						}
					});
				},
				fail(res) {
					console.log(`login 调用失败`);
				}
			});
		}
	}
};
</script>

<style lang="scss">
.bcg {
	width: 100%;
	height: 800rpx;
	position: relative;
}
.content {
	width: 100%;
	position: absolute;
	top: 248rpx;
	padding: 0rpx 40rpx;
	box-sizing: border-box;
	.imgblock {
		position: relative;
		image {
			width: 288rpx;
			height: 104rpx;
		}
		.ttt {
			position: absolute;
			top: 0%;
			left: 214rpx;
			width: 180rpx;
			height: 44rpx;
			background: #ffe3cf;
			border-radius: 20rpx 46rpx 46rpx 4rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 22rpx;
			color: #843700;
			line-height: 44rpx;
			text-align: center;
		}
	}
	.top_text {
		width: 670rpx;
		height: 68rpx;
		background: linear-gradient(251deg, #ffdec7 0%, #fff5de 100%);
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		border: 1px solid #ffffff;
		border-bottom: none;
		margin-top: 64rpx;
		padding: 0rpx 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #843700;
		box-sizing: border-box;
		line-height: 68rpx;
		margin-bottom: 20rpx;
	}
	.item_b {
		width: 670rpx;
		height: 160rpx;
		background: #ffffff;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		padding: 40rpx 32rpx;
		box-sizing: border-box;
		margin-top: 40rpx;
		image {
			width: 80rpx;
			height: 80rpx;
		}
		.tr {
			margin-left: 34rpx;
			flex: 1;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #11192d;
		}
	}
}
</style>
